/**
 * Copyright (C) 2010 DustedPixels.com
 */
package com.dustedpixels.cirt.model.cpu.z80;

import com.dustedpixels.cirt.model.core.Circuit;
import com.dustedpixels.cirt.model.core.In;
import com.dustedpixels.cirt.model.core.Out;
import com.dustedpixels.cirt.model.core.Pins;
import com.dustedpixels.cirt.model.core.Script;

/**
 * DataBus
 *
 * @author Michal Pociecha-Los (micapolos@gmail.com)
 */
@Circuit
public final class DataBus {
  public static final int SELECT_REGS_LO = 0;
  public static final int SELECT_REGS_HI = 1;
  public static final int SELECT_ACC = 2;
  public static final int SELECT_FLAGS = 3;
  public static final int SELECT_I = 4;
  public static final int SELECT_R = 5;
  
  @In @Pins(4) public int select;
  
  @In @Pins(8) public int regsLo;
  @In @Pins(8) public int regsHi;
  @In @Pins(8) public int acc;
  @In @Pins(8) public int flags;
  @In @Pins(8) public int i;
  @In @Pins(8) public int r;
  
  @Out @Pins(8) public int out;
  
  @Script
  public void update() {
    switch (select) {
      case SELECT_REGS_HI:
        out = regsHi;
        break;
      case SELECT_REGS_LO:
        out = regsLo;
        break;
      case SELECT_ACC:
        out = acc;
        break;
      case SELECT_FLAGS:
        out = flags;
        break;
      case SELECT_I:
        out = i;
        break;
      case SELECT_R:
        out = r;
        break;
    }
  }
}
